package com.service.impl;

import com.model.TestUser;
import com.dao.TestUserDao;

import com.service.TestUserService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by Administrator on 2018-8-9 0009.
 */

@Service("testUserService")
@Transactional
public class TestUserServiceImpl implements TestUserService {

    //log4j2使用LogManager初始化logger
    private static Logger log = LogManager.getLogger(TestUserServiceImpl.class);

    @Autowired
    private TestUserDao testUserDao;


    @Override
    @Transactional(readOnly = true)
    public TestUser getTestUserById(Integer userId) throws Exception {
        return testUserDao.selectByPrimaryKey(userId);
    }

    @Override
    public int insertTestUser(TestUser testUser) throws Exception {
        return testUserDao.insert(testUser);
    }

    @Override
    public int updateTestUser(TestUser testUser) throws Exception {
        return testUserDao.updateByPrimaryKey(testUser);
    }

    @Override
    @Transactional(readOnly = true)
    public List<TestUser> getAllList() throws Exception {
        return testUserDao.selectAll();
    }

    @Override
    public int deleteById(Integer userId) throws Exception {
        return testUserDao.deleteByPrimaryKey(userId);
    }

    @Override
    @Transactional(readOnly = true)
    public int selectCount() throws Exception {
        return testUserDao.selectCount();
    }

    @Override
    public TestUser getUserByName(String username) throws Exception {
        return testUserDao.selectByUsername(username);
    }


}
